#pragma once

#include <AVUIFrameworkElement.h>

namespace AVUI {


typedef void (*pfnParameterizedThreadStart)(Object* pContext);
typedef void (*pfnThreadStart)();

class Thread : public Object
{
public:
    Thread(pfnParameterizedThreadStart threadStart) : m_parameterizedThreadStart(threadStart) { }
    Thread(pfnThreadStart threadStart) : m_threadStart(threadStart), m_parameterizedThreadStart(NULL) { }


    void Start();
    void Start(Object* pParam);

    Thread* get_CurrentThread() { return m_pCurrentThread; }

private:
    void StartCommon();

    static unsigned long __stdcall CommonThreadProc(void* pParameter);

    pfnParameterizedThreadStart m_parameterizedThreadStart;
    pfnThreadStart m_threadStart;

    TRefCountedPtr<Object> m_pStartParameter;
    AVUI_THREAD_LOCAL static Thread* m_pCurrentThread;
};

}; // namespace AVUI


